package controller.webservice.bootstrap;

import java.io.IOException;

import manager.CourseMgr;
import controller.validator.CourseValidator;
import exception.InputValidationErrors;

/**
 * Validates and loads course CSV.
 * 
 * @author huangjm.2012, jaslin.wee.2012, sheryl.tay.2012
 * 
 */
public class CourseCsvLoader extends CsvLoader {

	private CourseMgr courseMgr;

	CourseCsvLoader(String pathToFile) throws IOException {
		super(pathToFile);
		courseMgr = new CourseMgr();
	}

	@Override
	boolean loadRow() throws InputValidationErrors {

		String courseCode = getValue("course");
		String title = getValue("title");
		String description = getValue("description");
		String school = getValue("school");
		String examDate = getValue("exam date");
		String examStartTime = getValue("exam start");
		String examEndTime = getValue("exam end");

		CourseValidator validator = new CourseValidator(courseCode, title,
				description, school, examDate, examStartTime, examEndTime);
		validator.performValidationBeforeAdding();

		return courseMgr.addCourse(validator.getCourse());

	}
}
